package com.openlogic.logic.mapstruct;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.dozer.Mapper;
import org.noear.solon.annotation.Component;

import com.openlogic.common.core.mapstruct.EntityMapper;
import com.openlogic.datasource.api.dto.DataColumnDto;
import com.openlogic.datasource.api.entity.DataColumnEntity;
import com.openlogic.datasource.api.vo.DataColumnVo;

/**
 * @ClassName: DataColumnMapperStruct
 * @Description: 元数据信息表 Mapper 实体映射
 * @author weiyongpeng
 * @date 2024年11月22日 上午9:10:46
 */
@Component
public class DataColumnMapperStruct implements EntityMapper<DataColumnDto, DataColumnEntity, DataColumnVo> {

	/**
     * dozer转换的核心mapper对象
     */
    public static final Mapper converter = new org.dozer.DozerBeanMapper();
    
	@Override
	public DataColumnDto toDTO(DataColumnEntity e) {
		return converter.map(e, DataColumnDto.class);
	}

	@Override
	public List<DataColumnDto> toDTO(List<DataColumnEntity> es) {
		return Optional.ofNullable(es)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, DataColumnDto.class))
		        .collect(Collectors.toList());	
	}

	@Override
	public DataColumnVo toVO(DataColumnEntity e) {
		return converter.map(e, DataColumnVo.class);
	}

	@Override
	public List<DataColumnVo> toVO(List<DataColumnEntity> es) {
		return Optional.ofNullable(es)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, DataColumnVo.class))
		        .collect(Collectors.toList());	
	}

	@Override
	public DataColumnEntity toEntity(DataColumnDto d) {
		return converter.map(d, DataColumnEntity.class);
	}

	@Override
	public List<DataColumnEntity> toEntity(List<DataColumnDto> ds) {
		return Optional.ofNullable(ds)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, DataColumnEntity.class))
		        .collect(Collectors.toList());	
	}
}
